/* This file was created by Nokia Developer's Suite for J2ME(TM) */

import java.util.*;
import javax.microedition.lcdui.*;

import localization.Language;
import localization.LocalizationManager;

public class Editor extends Form
{
    private TimeTable m_table;
    private int m_record;
    
    private final static Language language = LocalizationManager.getCurrentLanguageFromInstance();
    
    private DateField m_start=   new DateField( language.getBeginText() + ": ", DateField.TIME );
    private DateField m_end=     new DateField( language.getEndText() + ": ", DateField.TIME );
    private TextField m_lesson=  new TextField( language.getLessonText()+ ": ", "", 30, TextField.ANY );
    private TextField m_room=    new TextField( language.getRoomText() + ": ", "", 20, TextField.ANY );
    private TextField m_comment= new TextField( language.getCommentText() + ": ", "", 30, TextField.ANY );
    
    
    static public final Command m_OK=   new Command( language.getOkText(), Command.OK, 0);
    static public final Command m_back= new Command( language.getBackText(), Command.BACK, 0);
    
    
	public Editor( TimeTable t, int no,  Scheduler midlet )
	{
		super( language.getEditText() );
       
        m_table= t;
        m_record= no;
        
        if( m_table.IsSet(no))
        {
            m_start.setDate( m_table.GetStart( m_record ));
            m_end.setDate( m_table.GetEnd( m_record ) );
            m_lesson.setString( m_table.GetLesson(m_record) );
            m_room.setString( m_table.GetRoom(m_record) );
            m_comment.setString( m_table.GetComment(m_record) );
        }
        else
        {
            m_start.setDate( new Date(0));
            m_end.setDate( new Date(0) );
        }
        
        append( m_start );
        append( m_end );
        append( m_lesson );
        append( m_room );
        append( m_comment );
        
        addCommand( m_OK );
        addCommand( m_back );
        setCommandListener( midlet );
	}
    
    public void UpdateTable()
    {
        m_table.SetCell(m_record, m_lesson.getString(), m_room.getString(), m_comment.getString(), m_start.getDate(), m_end.getDate() );
    }


}